//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using CommunityServer.Components;

namespace CommunityServer
{
    public class UserQuery
    {
        public int PageIndex;
        public int PageSize = 20;
        public SortUsersBy SortBy = SortUsersBy.Username;
        public SortOrder Order = SortOrder.Ascending;
        public string SearchText;
        public bool SearchEmail = true;
		public bool SearchUsername = true;
        public UserAccountStatus Status = UserAccountStatus.Approved;
        public bool IncludeRecordCount = true;
        public bool IncludeHiddenUsers = false;
        public Guid RoleID = Guid.Empty;
		public int JoinedDateComparer;
		public int LastPostDateComparer;

		private bool hasJoinedDate = false;
		private bool hasPostDate = false;
		private DateTime joinedDate = DateTime.MinValue;
		private DateTime lastPostDate = DateTime.MinValue;

		public DateTime JoinedDate
		{
			get{ return joinedDate; }
			set
			{ 
				joinedDate = value;
				hasJoinedDate = value == DateTime.MinValue ? false : true;
			}
		}

		public DateTime LastPostDate
		{
			get{ return lastPostDate; }
			set
			{ 
				lastPostDate = value;
				hasPostDate = value == DateTime.MinValue ? false : true;
			}
		}

		public bool HasJoinedDate { get{ return hasJoinedDate; } }
		public bool HasPostDate { get{ return hasPostDate; } }


		// This is to allow a SQL sort express to be provided (from a CA Grid control most likely)
		//	taht will override the SortBy and Order properties above
		public string SortClauseOverride;

        public string Key
        {
            get { return string.Format("PI{0}PS{1}SB{2}SO{3}ST{4}SUN{5}S{6}H{7}SID{8}RID{9}SEN{10}JD{11}JC{12}PD{13}PC{14}SCO{15}", 
					  this.PageIndex,this.PageSize,this.SortBy,this.Order,this.SearchText,this.SearchUsername,this.Status,this.IncludeHiddenUsers, CSContext.Current.SettingsID, this.RoleID.ToString(), this.SearchEmail, this.JoinedDate.ToString(), this.JoinedDateComparer, this.LastPostDate.ToString(), this.LastPostDateComparer, this.SortClauseOverride);}
        }

    }
}